home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Atlanta_1990 / Atlanta-Devcon.1 / Libraries / Workbench / AppMenu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-26  |  3.8 KB  |  115 lines

  1. /***********************************************************************
  2.  *                                                                     *
  3.  *                            COPYRIGHTS                               *
  4.  *                                                                     *
  5.  *   Copyright (c) 1990  Commodore-Amiga, Inc.  All Rights Reserved.   *
  6.  *                                                                     *
  7.  **********************************************************************/
  8.  
  9. /*
  10.  * Code test test AppMenu feature of Workbench
  11.  */
  12.  
  13.  
  14. #include <intuition/intuition.h>
  15. #include <exec/memory.h>
  16. #include <workbench/startup.h>
  17. #include <workbench/workbench.h>
  18.  
  19. #include <stdio.h>
  20.  
  21. #include <clib/exec_protos.h>
  22. #include <clib/intuition_protos.h>
  23. #include <clib/icon_protos.h>
  24. #include <clib/wb_protos.h>
  25. #include <clib/dos_protos.h>
  26.  
  27. struct IntuitionBase *IntuitionBase;
  28. struct WorkbenchBase *WorkbenchBase;
  29. struct IconBase *IconBase;
  30.  
  31. void            main(void);
  32.  
  33. void
  34. main(void)
  35. {
  36.   struct MsgPort *msgport;
  37.   struct Window  *win;
  38.   struct AppMenuItem *ami1, *ami2;
  39.   struct IntuiMessage *imsg;
  40.   struct AppMessage *amsg;
  41.   struct WBArg   *argptr;
  42.  
  43.   ULONG           id = 1, userdata = 0;
  44.   BOOL            done = FALSE;
  45.   int             i;
  46.  
  47.   printf("am: enter\n");
  48.  
  49.   if (IntuitionBase = OpenLibrary("intuition.library", 36)) {
  50.     if (WorkbenchBase = OpenLibrary("workbench.library", 36)) {
  51.       if (IconBase = OpenLibrary("icon.library", 36)) {
  52.     if (msgport = CreateMsgPort()) {
  53.       if (win = OpenWindowTags(NULL,
  54.                    WA_Left, 0,
  55.                    WA_Top, 1,
  56.                    WA_Width, 160,
  57.                    WA_Height, 50,
  58.                    WA_IDCMP, CLOSEWINDOW,
  59.                    WA_Flags, WINDOWCLOSE | WINDOWDRAG,
  60.                    WA_Title, "AppMenu",
  61.                    TAG_END)) {
  62.  
  63.         printf("am: calling AddAppMenuItem for ami1...\n");
  64.         if (ami1 = AddAppMenuItem(id, userdata, "appmenuitem1", msgport, NULL)) {
  65.               printf("am: calling AddAppMenuItem for ami2...\n");
  66.           if (ami2 = AddAppMenuItem(85, 55, "appmenuitem2", msgport, NULL)) {
  67.         printf("ami: ok, ami1 %lx, ami2 %lx, going to sleep...\n", ami1, ami2);
  68.         do {
  69.           Wait(1 << win->UserPort->mp_SigBit | 1 << msgport->mp_SigBit);
  70.           while (imsg = (struct IntuiMessage *) GetMsg(win->UserPort)) {
  71.             if (imsg->Class = CLOSEWINDOW)
  72.               done = TRUE;
  73.             ReplyMsg((struct Message *) imsg);
  74.           }
  75.           while (amsg = (struct AppMessage *) GetMsg(msgport)) {
  76.             printf("am: appmsg=%lx, Type=%ld, ID=%ld, UserData=%ld, NumArgs=%ld\n", amsg, amsg->am_Type, amsg->am_ID, amsg->am_UserData, amsg->am_NumArgs);
  77.             argptr = amsg->am_ArgList;
  78.             for (i = 0; i < amsg->am_NumArgs; i++) {
  79.               printf("\targ(%ld): Name='%s', Lock=%lx\n", i, argptr->wa_Name, argptr->wa_Lock);
  80.               argptr++;
  81.             }
  82.             ReplyMsg((struct Message *) amsg);
  83.           }
  84.         } while (!done);
  85.  
  86.         printf("ami: calling RemoveAddMenuItem for ami2\n");
  87.         RemoveAppMenuItem(ami2);
  88.           } else        /* !ami2 */
  89.         printf("Couldn't AddAppMenuItem ami2\n");
  90.           printf("ami: calling RemoveAddMenuItem for ami1\n");
  91.           RemoveAppMenuItem(ami1);
  92.         } else        /* !ami1 */
  93.           printf("Couldn't AddAppMenuItem ami1\n");
  94.         CloseWindow(win);
  95.       } else        /* !win */
  96.         printf("Couldn't open window\n");
  97.           /* Make sure there are no more outstanding messages */
  98.           while(amsg = (struct AppMessage *)GetMsg(msgport))
  99.             ReplyMsg((struct Message *)amsg);
  100.       DeleteMsgPort(msgport);
  101.     } else            /* !msgport */
  102.       printf("Coulnd't create messageport\n");
  103.     CloseLibrary(IconBase);
  104.       } else            /* !IconBase */
  105.     printf("Couldn't open icon.library\n");
  106.       CloseLibrary(WorkbenchBase);
  107.     } else            /* !WorkbenchBase */
  108.       printf("Couldn't open workbench.library\n");
  109.     CloseLibrary(IntuitionBase);
  110.   } else            /* !IntuitionBase */
  111.     printf("Couldn't open intuition.library\n");
  112.   printf("am: done\n");
  113. }
  114.  
  115.